package net.tv90.bfmccore.util.area;

import lombok.Data;
import net.tv90.bfmccore.util.vector.Vector2i;
import net.tv90.bfmccore.util.vector.Vector3i;

@Data
public class RectangleArea2i implements Area {

    //矩形区域的两个顶点
    private Vector2i vertex1;
    private Vector2i vertex2;

    public RectangleArea2i(Vector2i vertex1, Vector2i vertex2) {
        this.vertex1 = vertex1;
        this.vertex2 = vertex2;
    }

    @Override
    public boolean isInArea(Vector3i point3i) {
        Vector2i point = point3i.reduction();
        if (point == null) return false;
        int x = point.getX();
        int y = point.getY();
        int x1 = vertex1.getX();
        int y1 = vertex1.getY();
        int x2 = vertex2.getX();
        int y2 = vertex2.getY();
        return x >= Math.min(x1, x2) && x <= Math.max(x1, x2)
                && y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
    }
}
